package com.cn.controller;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class PublisherController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/testSimpleQueue")
    public void testSimpleQueue() {
        // 队列名称
        String queueName = "simple.queue";
        // 消息
        for (int i = 0; i < 50; i++) {
            // 发送消息
            String message = "hello, spring amqp!"+i;
            rabbitTemplate.convertAndSend(queueName, message);
        }

    }

    @GetMapping("/testFanoutExchange")
    public void testFanoutExchange() {
        // 队列名称
        String exchangeName = "itcast.fanout";
        // 消息
        String message = "hello, everyone!";
        rabbitTemplate.convertAndSend(exchangeName, "", message);
    }
}
